package com.nazca.tvremote.activity;

import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.View;
import android.view.WindowManager;

import com.nazca.tvremote.R;
import com.nazca.tvremote.service.Controller;
import com.nazca.tvremote.view.TVRemoteControl;
import com.nazca.tvremote.view.TVRemoteNum;
import com.nazca.tvremote.view.TitleBar;
import com.nazca.tvremote.widget.TabActivity;
import com.nazca.tvremote.widget.TabHost;
import com.nazca.tvremote.widget.TabHost.OnTabChangeListener;

public class TVRemoteActivity extends TabActivity implements OnTabChangeListener {
	
	private TitleBar mTitleBar;
	
	private Controller mController;
	
	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		
		getWindow().setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_STATE_HIDDEN); 
		
		TabHost tabHost = getTabHost();
		tabHost.setOnTabChangedListener(this);
        
        LayoutInflater.from(this).inflate(R.layout.tv_remote, tabHost.getTabContentView(), true);

        tabHost.addTab(tabHost.newTabSpec(getString(R.string.tv_remote_num))
                .setIndicator(getString(R.string.tv_remote_num))
                .setContent(R.id.tv_remote_num));
        tabHost.addTab(tabHost.newTabSpec(getString(R.string.tv_remote_control))
                .setIndicator(getString(R.string.tv_remote_control))
                .setContent(R.id.tv_remote_control));
        tabHost.addTab(tabHost.newTabSpec(getString(R.string.tv_remote_service))
        		.setIndicator(getString(R.string.tv_remote_service))
        		.setContent(R.id.tv_remote_service));
        
        mTitleBar = (TitleBar) findViewById(R.id.title_bar);
        mTitleBar.getBackButton().setText(R.string.main_tv_remote);
		mTitleBar.getBackButton().setOnClickListener(new View.OnClickListener(){
			public void onClick(View v) {
				finish();
			}
		});
		
		mController = Controller.getInstance(this);
		((TVRemoteNum)findViewById(R.id.tv_remote_num)).setController(mController);
		((TVRemoteControl)findViewById(R.id.tv_remote_control)).setController(mController);
	}

	@Override
	public void onTabChanged(String tabId) {
		TabHost tabHost = getTabHost();
		int currentTab = tabHost.getCurrentTab();
		int resid = R.drawable.bg_tab_widget_left;
		switch (currentTab) {
			case 0:
				resid = R.drawable.bg_tab_widget_left;
				break;
			case 1:
				resid = R.drawable.bg_tab_widget_middle;
				break;
			case 2:
				resid = R.drawable.bg_tab_widget_right;
				break;
	
			default:
				break;
		}
		tabHost.getTabWidget().setBackgroundResource(resid);
	}
	
}
